﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.CompilerServices;

using IBApi;

namespace IBRx {
	public class IBMarketData : IBResponse { }

	public class TickPrice : IBMarketData {
		public int TickerId { get; private set; }
		public TickTypeEnum Field { get; private set; }
		public double Price { get; private set; }
		public int CanAutoExecute { get; private set; }

		[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
		public TickPrice(int tickerId, int field, double price, int canAutoExecute) {
			this.TickerId = tickerId;
			this.Field = (TickTypeEnum)Enum.ToObject(typeof(TickTypeEnum), field);
			this.Price = price;
			this.CanAutoExecute = canAutoExecute;
		}
	}

	public class TickSize : IBMarketData {
		public int TickerId { get; private set; }
		public TickTypeEnum Field { get; private set; }
		public double Size { get; private set; }

		[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
		public TickSize(int tickerId, int field, double size) {
			this.TickerId = tickerId;
			this.Field = (TickTypeEnum)Enum.ToObject(typeof(TickTypeEnum), field);
			this.Size = size;
		}
	}

	public class TickString : IBMarketData {
		public int TickerId { get; private set; }
		public TickTypeEnum Field { get; private set; }
		public string Value { get; private set; }

		[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
		public TickString(int tickerId, int field, string value) {
			this.TickerId = tickerId;
			this.Field = (TickTypeEnum)Enum.ToObject(typeof(TickTypeEnum), field);
			this.Value = value;
		}
	}

	public class TickGeneric : IBMarketData {
		public int TickerId { get; private set; }
		public TickTypeEnum Field { get; private set; }
		public double Value { get; private set; }

		[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
		public TickGeneric(int tickerId, int field, double value) {
			this.TickerId = tickerId;
			this.Field = (TickTypeEnum)Enum.ToObject(typeof(TickTypeEnum), field);
			this.Value = value;
		}
	}

	public class TickEFP : IBMarketData {
		public int TickerId { get; private set; }
		public TickTypeEnum TickType { get; private set; }
		public double basisPoints  { get; private set;}
		public string FormattedBasisPoints { get; private set;}
		public double ImpliedFuture { get; private set;}
		public int HoldDays { get; private set;}
		public string FutureExpiry { get; private set;}
		public double DividendImpact { get; private set;}
		public double DividendsToExpiry { get; private set; }

		[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
		public TickEFP(int tickerId, int tickType, double basisPoints, string formattedBasisPoints, double impliedFuture, int holdDays, string futureExpiry, double dividendImpact, double dividendsToExpiry) {
			this.TickerId = tickerId;
			this.TickType = (TickTypeEnum)Enum.ToObject(typeof(TickTypeEnum), tickType);
			this.basisPoints = basisPoints;
			this.FormattedBasisPoints = formattedBasisPoints;
			this.ImpliedFuture = impliedFuture;
			this.HoldDays = holdDays;
			this.FutureExpiry = futureExpiry;
			this.DividendImpact = dividendImpact;
			this.DividendsToExpiry = dividendsToExpiry;
		}
	}

	public class TickOptionComputation : IBMarketData {
		public int TickerId  { get; private set; }
		public TickTypeEnum Field { get; private set; }
		public double ImpliedVolatility { get; private set; }
		public double Delta { get; private set; }
		public double OptPrice { get; private set; }
		public double PvDividend { get; private set; }
		public double Gamma { get; private set; }
		public double Vega { get; private set; }
		public double Theta { get; private set; }
		public double UndPrice { get; private set; }

		[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
		public TickOptionComputation(int tickerId, int field, double impliedVolatility, double delta, double optPrice, double pvDividend, double gamma, double vega, double theta, double undPrice) {
			this.TickerId = tickerId;
			this.Field = (TickTypeEnum)Enum.ToObject(typeof(TickTypeEnum), field);
			this.ImpliedVolatility = impliedVolatility;
			this.Delta = delta;
			this.OptPrice = optPrice;
			this.PvDividend = pvDividend;
			this.Gamma = gamma;
			this.Vega = vega;
			this.Theta = theta;
			this.UndPrice = undPrice;
		}
	}

	public class TickSnapshotEnd : IBMarketData {
		public int TickerId { get; private set; }

		[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
		public TickSnapshotEnd(int tickerId) {
			this.TickerId = tickerId;
		}
	}

	public class DeltaNeutralValidation : IBMarketData {
		public int ReqId { get; private set; }
		public UnderComp UnderComp { get; private set; }
		public int ConId { get; private set; }
		public double Delta { get; private set; }
		public double Price { get; private set; }

		[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
		public DeltaNeutralValidation(int reqId, UnderComp underComp) : this(reqId, underComp.ConId, underComp.Delta, underComp.Price) {
			this.UnderComp = underComp;
		}

		[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
		protected DeltaNeutralValidation(int reqId, int conId, double delta, double price) {
			this.ReqId = reqId;
			this.ConId = conId;
			this.Delta = delta;
			this.Price = price;
		}
	}

	public class MarketDataType : IBMarketData {
		public int ReqId { get; private set; }
		public MarketDataTypeEnum MarketDataTypeId { get; private set; }

		[MethodImplAttribute(MethodImplOptions.AggressiveInlining)]
		public MarketDataType(int reqId, int marketDataType) {
			this.ReqId = reqId;
			this.MarketDataTypeId = (MarketDataTypeEnum) Enum.ToObject(typeof(MarketDataTypeEnum), marketDataType);
		}
	}
}
